{include file="public/head"/}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">编辑广告</div>
                <div class="layui-card-body" pad15>
                    <div class="layui-form" wid100 lay-filter="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">所属位置</label>
                            <div class="layui-input-inline">
                                <select name="ad_postion_id" lay-verify="required">
                                    <option value="">请选择所属广告位</option>
                                    {volist name="adsense" id="vo"}
                                    <option {if isset($info)&&($info.ad_postion_id eq $vo.ad_postion_id)}selected{/if} value="{$vo.ad_postion_id}">{$vo.name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">广告名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" lay-verify="required" value="{$info.name|default=''}" placeholder="{:lang('pleaseEnter')}广告名称" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">关联商品ID</label>
                            <div class="layui-input-inline">
                                <input type="number" name="goods_id" lay-verify="required" value="{$info.goods_id|default=''}" placeholder="{:lang('pleaseEnter')}广告名称" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">上传图片</label>
                            <div class="layui-input-inline">
                                <input name="image" id="image" placeholder="图片地址" value="{$info.image|default=''}" class="layui-input">
                            </div>
                            <div class="layui-input-inline layui-btn-container" style="width: auto;">
                                <button type="button" class="layui-btn" id="picUpload">
                                    <i class="layui-icon">&#xe67c;</i>上传图片
                                </button>
                                <button class="layui-btn layui-btn-primary picShow">查看图片</button >
                            </div>
                        </div>


                        <div class="layui-form-item">
                            <label class="layui-form-label">是否启用</label>
                            <div class="layui-input-block">
                                <input type="radio" name="status" {if((isset($info)&&$info.status == 1))||empty($info)}checked {/if} value="1" title="启用">
                                <input type="radio" name="status" {if(isset($info)&&$info.status == 0)}checked {/if} value="0" title="禁用">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="hidden" name="id" value="{$info.ad_id|default=''}">
                                <button class="layui-btn" lay-submit lay-filter="edit-but">确认保存</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

{include file="public/foot"/}
<script src="/static/vend/kindeditor/kindeditor-min.js" type="text/javascript"></script>
<script language="javascript">
    var editor;
    KindEditor.ready(function(K) {
        editor = K.create('.editor', {
            resizeType: 1,
            allowPreviewEmoticons: false,
            allowImageUpload: false,
            afterBlur: function() {
                this.sync();
            }
        });
    });
</script>
<script>
    layui.config({
        base: '__LAYDMIN__/',{if config('app.app_debug')}version: true{/if}
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','admin', 'table', 'util','upload'],function(){
        var $ = layui.$, admin = layui.admin, table = layui.table, element = layui.element, form = layui.form,util = layui.util, upload = layui.upload;
        var uri="{if isset($id)}{:url(SYS_PATH.'/'.CONTROLLER.'/edit')}{else}{:url(SYS_PATH.'/'.CONTROLLER.'/add')}{/if}";
        form.on('submit(edit-but)', function (data) {
            admin.req({
                url: uri,
                type: 'post',
                data: data.field,
                success: function (res) {
                    if(res.code==0){
                        window.top.layer.msg(res.msg, {icon: 1, time: 1000,shade:[0.5,'#000000']}, function () {
                            layer.closeAll("iframe");
                            //刷新父页面
                            parent.location.reload();
                        });
                    }else{
                        window.top.layer.msg(res.msg, {icon: 2, time: 1000,shade:[0.5,'#000']});
                        return;
                    }
                }
            });
        });
			
		//上传图片
		var pic = $('#image');
		upload.render({
			url: '{:url(SYS_PATH."/uploads/upimg")}'
			, elem: '#picUpload'
			, done: function (res) {
				if (res.code == 0) {
					pic.val(res.url);
				} else {
					layer.msg(res.msg, {icon: 5});
				}
			}
		});	
		
		 //监听查看图片按钮
		$('.picShow').on('click', function () {
            var src = pic.val();
            layer.photos({
                photos: {
                    "title": "查看图片" //相册标题
                    , "data": [{
                        "src": src //原图地址
                    }]
                }
                , shade: 0.5
                , closeBtn: 1
                , anim: 5
            });
		});
	});
</script>
</body>
</html>